package com.shenmazong.servertalkadmin.controller;

import com.shenmazong.servertalkadmin.service.TbSubjectService;
import com.shenmazong.utils.ResponseResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "接口-科目管理微服务")
public class SubjectController {

    @Autowired
    TbSubjectService tbSubjectService;

    /**
     * TODO addSubjectUser 增加科目
     * @return
     */
    @PostMapping(value = "/addSubjectUser")
    @ApiOperation(value = "添加科目", notes = "管理员添加科目")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="subjectName", value = "科目名称", dataType = "String", required=true)
    })
    public ResponseResult addSubjectUser(@RequestParam("subjectName") String subjectName) {
        return tbSubjectService.addSubjectUser(subjectName);
    }

    /**
     * TODO delSubjectUser 删除科目
     * @return
     */
    @ApiOperation(value = "删除科目", notes = "管理员删除科目")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "subjectId", value = "科目ID", dataType = "int", required = true, example = "0")
    })
    @PostMapping(value = "/delSubjectUser")
    public ResponseResult delSubjectUser(@RequestParam("subjectId") Integer subjectId) {
        return tbSubjectService.delSubjectUser(subjectId);
    }

    /**
     * TODO 修改科目信息
     * @return
     */
    @ApiOperation(value = "修改科目", notes = "管理员修改科目信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "subjectId", value = "科目ID", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "subjectName", value = "科目名称", dataType = "String", required = true)
    })
    @PostMapping(value = "/setSubjectInfo")
    public ResponseResult setSubjectInfo(@RequestParam("subjectId") Integer subjectId,
                                         @RequestParam("subjectName") String subjectName) {
        return tbSubjectService.setSubjectInfo(subjectId, subjectName);
    }

    /**
     * TODO getSubjectInfo 获取科目信息
     * @param subjectId
     * @return
     */
    @ApiOperation(value = "获取科目信息", notes = "管理员根据科目ID获取科目信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "subjectId", value = "科目ID", dataType = "int", required = true, example = "0")
    })
    @GetMapping(value = "/getSubjectInfo")
    public ResponseResult getSubjectInfo(@RequestParam("subjectId") Integer subjectId) {
        return tbSubjectService.getSubjectInfo(subjectId);
    }

    /**
     * TODO getSubjectAll 获取科目列表
     * @return
     */
    @ApiOperation(value = "获取科目列表", notes = "管理员获取科目列表")
    @GetMapping(value = "/getSubjectAll")
    public ResponseResult getSubjectAll() {
        return tbSubjectService.getSubjectAll();
    }
}
